﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

class MenuEntry
{
    string text;
    public string Text
    {
        get { return text; }
        set { text = value; }
    }

    SpriteFont spriteFont;
    public SpriteFont Font
    {
        get { return spriteFont; }
        set { spriteFont = value; }
    }

    Vector2 position;
    public Vector2 Position
    {
        get { return position; }
        set { position = value; }
    }

    private string description;
    public string Description
    {
        get { return description; }
        set { description = value; }
    }

    private Texture2D texture;
    public Texture2D Texture
    {
        get { return texture; }
        set { texture = value; }
    }

    private Texture2D selectedTexture;
    public Texture2D SelectedTexture
    {
        get { return selectedTexture; }
        set { selectedTexture = value; }
    }

 
    public event EventHandler<EventArgs> Selected;

    protected internal virtual void OnSelectEntry()
    {
        if (Selected != null)
            Selected(this, EventArgs.Empty);
    }

    /// <summary>
    /// Constructs a new menu entry with the specified text.
    /// </summary>
    public MenuEntry(string text)
    {
        this.text = text;
    }


    public virtual void Update(MenuScreen screen, bool isSelected, GameTime gameTime)
    { }

    public virtual void Draw(MenuScreen screen, bool isSelected, GameTime gameTime)
    {
        // Draw the selected entry in yellow, otherwise white.
        Color color = isSelected ? Color.Red : Color.White;

        // Draw text, centered on the middle of each line.
        ScreenManager screenManager = screen.ScreenManager;
        SpriteBatch spriteBatch = screenManager.SpriteBatch;

        if(!isSelected && texture != null)
            spriteBatch.Draw(texture, position, Color.White);
        if(isSelected)
            spriteBatch.Draw(selectedTexture, position, Color.White);

        if ((spriteFont != null) && !String.IsNullOrEmpty(text) && texture != null)
        {
            Vector2 textSize = spriteFont.MeasureString(text);
            Vector2 textPosition = position + new Vector2(
                (float)Math.Floor((texture.Width - textSize.X) / 2),
                (float)Math.Floor((texture.Height - textSize.Y) / 2));
            spriteBatch.DrawString(spriteFont, text, textPosition, color);
        }
        
        /*if ((spriteFont != null) && !String.IsNullOrEmpty(text))
        {
            spriteBatch.DrawString(spriteFont, text, position, color);
        }*/
    }

}
